package com.ys.service.business.impl;

import java.util.Map;

import com.ys.mapper.business.TcwVatPaymentAccountMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.ys.dto.AddDto;
import com.ys.entity.business.TcwVatPaymentAccount;
import com.ys.entity.sys.TsUserChange;
import com.ys.service.business.TcwVatPaymentAccountService;
import com.ys.util.shiro.ShiroUtils;
import com.ys.vo.R;



@Service("TcwVatPaymentAccountService")
public class TcwVatPaymentAccountImpl implements TcwVatPaymentAccountService {

    @Autowired
    private TcwVatPaymentAccountMapper tcwVatPaymentAccountMapper;

    /**
     * 新增
     * @param params
     * @return
     * @throws Exception
     */
    @Override
    public R add(Map<String, Object> params) throws Exception {

        TcwVatPaymentAccount tcwVatPaymentAccount = JSON.parseObject(JSON.toJSONString(params), TcwVatPaymentAccount.class);
//        //生成编码
//        String codeTop = "ZHBM";
//        TcwVatPaymentAccount tcwVatPaymentAccountMax = new TcwVatPaymentAccount().setOrderby("A.Id DESC").queryFirst();
//        if(tcwVatPaymentAccountMax!=null && tcwVatPaymentAccountMax.getCode()!=null ){
//            long id = tcwVatPaymentAccountMax.getId();
//            long codeNum = id ;//编码从0开始，比id少1
//            String codeStr = codeNum+"";
//            if(codeNum<10000){
//                codeStr = String.format("%0"+5+"d", codeNum);//小于3位在前面补0
//            }
//            tcwVatPaymentAccount.setCode(codeTop+codeStr);
//        }else {
//            tcwVatPaymentAccount.setCode("ZHBM00001");
//        }
        String loginUserId = ShiroUtils.getUserId();
        TsUserChange tsUserChange = new TsUserChange().setUserId(loginUserId).setStatus(1).queryFirst();
        tcwVatPaymentAccount.setCreateChangeld(tsUserChange.getId());

        tcwVatPaymentAccountMapper.insert(tcwVatPaymentAccount);
        return R.ok(AddDto.closeAndReload());
    }

    /**
     * 修改
     * @param params
     * @return
     * @throws Exception
     */
    @Override
    public R edit(Map<String, Object> params) throws Exception {


        TcwVatPaymentAccount tcwVatPaymentAccount = JSON.parseObject(JSON.toJSONString(params), TcwVatPaymentAccount.class);

        tcwVatPaymentAccountMapper.update(tcwVatPaymentAccount);
        return R.ok(AddDto.closeAndReload());
    }



}
